package com.version.manager.service.Shop;

import com.version.manager.entity.Shop.shopGoods;
import com.version.manager.entity.Shop.viewShopGoods;
import com.version.manager.mapper.Shop.shopGoodsMapper;
import com.version.manager.model.Msg;
import com.version.manager.service.BaseService;
import com.version.manager.util.QueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class shopGoodsService extends BaseService<shopGoodsMapper, shopGoods> {
    @Autowired
    private shopGoodsMapper mapper;

    public Msg save(shopGoods goods) throws Exception {
        return super.saveOrUpdate(goods);
    }

    public Msg del(String id) throws Exception {
        shopGoods e=new shopGoods();
        e.setId(id);
        return super.delete(e,false);
    }
    @Cacheable(value = "goodsBanner",key = "'goodsBanner_'.concat(#root.args[0])",sync=true)
    public Msg getBanner(String categoryId){
        Map<String,Object> map=new HashMap<>();
        map.put("isBanner",1);
        map.put("goodsCategory",categoryId);
        QueryParam param=new QueryParam(map);
        List<shopGoods> list= super.selectList(param);
        return Msg.success().addData(list);
    }
    @Cacheable(value = "goods",key = "'goods_'.concat(#root.args[0])",sync=true)
    public Msg getGoods(String id){
        shopGoods goods=super.selectById(id);
        return Msg.success().addData(goods);
    }


}
